package edu.fiu.cs.alg.clustering;

import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

import org.junit.Test;

import edu.fiu.cs.core.Cluster;
import edu.fiu.cs.core.DoubleArray;
import Network.Node;

public class TestAlgoKMeans {

	@Test
	public static void testRunAlgorithm() {
		//initialize the list of nodes, which can be populated from file
		// all the nodes have different ip address
		ArrayList<Node> nodes = new ArrayList<Node>();
		Random rand = new Random();
		for(int i=0;i<100;i++){
			Node node = new Node();
			node.setId(i);
			node.setiPAddress("10.0.0."+i);
			node.setNumOfInflow(rand.nextInt());
			node.setNumOfOutflow(rand.nextInt());
			node.setBytesReceived(rand.nextInt());
			node.setBytesSent(rand.nextInt());
			
			nodes.add(node);
		}
		// Each node has four attributes to do clustering: NumOfInFlow, NumOfOutFlow,bytesRecieved, byteSent.
		// Their weights for calculating distance are stored in the following array.
		// This weights can be provided by a user
		double [] weights = {0.25,0.25,0.25,0.25};
		DoubleArray doubleArray = new DoubleArray(weights);
		// K is used to specify the number of group
		// This parameters can be provided by a user
		int k = 4;
		//initialize the KMeans algorithm
		AlgoKMeans kmeans = new AlgoKMeans();
		// do clustering, and then return a list of clusters
		List<Cluster> clusters = kmeans.runAlgorithm(nodes, doubleArray, k);
		for(int i=0;i<clusters.size();i++){
			System.out.println(clusters.get(i));
		}
	}
        
        
       public List<Cluster> computeCluster(ArrayList<Node> nodes, double[] weights, int clusterSize){
           //initialize the list of nodes, which can be populated from file
		// all the nodes have different ip address
		/*ArrayList<Node> nodes = new ArrayList<Node>();
		Random rand = new Random();
		for(int i=0;i<100;i++){
			Node node = new Node();
			node.setId(i);
			node.setiPAddress("10.0.0."+i);
			node.setNumOfInflow(rand.nextInt());
			node.setNumOfOutflow(rand.nextInt());
			node.setBytesReceived(rand.nextInt());
			node.setBytesSent(rand.nextInt());
			
			nodes.add(node);
		}*/
		// Each node has four attributes to do clustering: NumOfInFlow, NumOfOutFlow,bytesRecieved, byteSent.
		// Their weights for calculating distance are stored in the following array.
		// This weights can be provided by a user
		/*double [] weights = {0.25,0.25,0.25,0.25};*/
		DoubleArray doubleArray = new DoubleArray(weights);
		// K is used to specify the number of group
		// This parameters can be provided by a user
		//int k = 4;
                int k = clusterSize;
		//initialize the KMeans algorithm
		AlgoKMeans kmeans = new AlgoKMeans();
		// do clustering, and then return a list of clusters
		List<Cluster> clusters = kmeans.runAlgorithm(nodes, doubleArray, k);
		for(int i=0;i<clusters.size();i++){
			System.out.println(clusters.get(i));
		}
           
           return clusters;
       }

        
        public static void main(String args[]){
            TestAlgoKMeans.testRunAlgorithm();
        }
	

}
